﻿using System.Linq.Expressions;

namespace Exam.Service
{
   
        public interface IRepository<T>
        {
            
            /// <summary>
            /// 获取所有信息
            /// </summary>
            /// <returns></returns>
            public List<T> GetAll();

            /// <summary>
            /// 通过ID查找信息
            /// </summary>
            /// <param name="id"></param>
            /// <returns></returns>
            public T GetById(int id);


            /// <summary>
            /// 级联查询，o=>o.xxx表达式
            /// </summary>
            /// <param name="includes">o=>o.xxx表达式</param>
            /// <returns>List</returns>
            public List<T> GetInclude(params Expression<Func<T, object>>[] includes);

            /// <summary>
            /// 条件查询，o=>o.xxx=xxx表达式
            /// </summary>
            /// <param name="whereLlambda">o=>o.xxx=xxx表达式</param>
            /// <returns>List</returns>
            public List<T> GetCondition(params Expression<Func<T, bool>>[] whereLambda);

            /// <summary>
            /// 条件查询并进行排序，true为升序
            /// </summary>
            /// <typeparam name="Tkey">排序条件字段类型</typeparam>
            /// <param name="whereLambda">查询条件o=>o.xxx=xxx表达式</param>
            /// <param name="isAsc">是否升序</param>
            /// <param name="orderbyLambda">排序条件o=>o.xxx</param>
            /// <returns>List</returns>
            public List<T> GetConditionOederby<Tkey>(Expression<Func<T, bool>> whereLambda,
                bool isAsc, Expression<Func<T, Tkey>> orderbyLambda);

     

            /// <summary>
            /// 添加
            /// </summary>
            /// <param name="entity">数据实体</param>
            /// <returns>添加后的数据实体</returns>
            /// 
            public T Add(T entity);
            /// <summary>
            /// 添加
            /// </summary>
            /// <param name="entity">数据实体</param>
            /// <returns>成功/失败</returns>
            /// 
            public bool AddOk(T entity);
            /// <summary>
            /// 更新
            /// </summary>
            /// <param name="entity">数据实体</param>
            /// <returns>更新后的数据实体</returns>
            public T Update(T entity);

            /// <summary>
            /// 更新
            /// </summary>
            /// <param name="entity">数据实体</param>
            /// <returns>成功/失败</returns>
            public bool UpdateOk(T entity);

            /// <summary>
            /// 删除
            /// </summary>
            /// <param name="id"></param>
            /// <returns></returns>
            public bool Delete(int id);
        }
    }
